﻿Imports MySql.Data.MySqlClient
Public Class frmrpt_gatin
    Dim mysql As MySqlConnection = main_form.mysqlconection
    Dim mySqlCommand As New MySqlCommand
    Dim mySqlAdaptor As New MySqlDataAdapter
    Dim mySqlReader As MySqlDataReader
    Dim rpt1 As New rpt_gateinrpt
    Private Sub frmrpt_gatin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        CrystalReportViewer1.ReportSource = rpt1


        CrystalReportViewer1.Refresh()
        System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US")
        System.Threading.Thread.CurrentThread.CurrentUICulture = System.Threading.Thread.CurrentThread.CurrentCulture
        mysql.Close()
        If mysql.State = ConnectionState.Closed Then
            mysql.Open()
        End If
        mySqlCommand.CommandText = "Select * from borrow join booking on borrow.BOOKID = booking.BOOKINGID join voyage on voyage.VOYAGEID = booking.BVOYAGE  join shipper on shipper.SHIPPERID = booking.BSHIP join ctnmain on ctnmain.CTNMAINID = borrow.CTNID   where idborrow ='" & frmview_voyage.idborrow & "' ;"
        ' mySqlCommand.CommandText = 
        mySqlCommand.Connection = mysql
        mySqlAdaptor.SelectCommand = mySqlCommand

        Try
            mySqlReader = mySqlCommand.ExecuteReader

            While (mySqlReader.Read())
                If mySqlReader("REMARK") Is DBNull.Value Then
                    rpt1.SetParameterValue("remark", "-")
                Else
                    rpt1.SetParameterValue("remark", mySqlReader("REMARK"))
                End If
                rpt1.SetParameterValue("comudity", mySqlReader("BCOM"))

                rpt1.SetParameterValue("dateday", " ")
                rpt1.SetParameterValue("datetime", " ")
                rpt1.SetParameterValue("bookno", " ")
                rpt1.SetParameterValue("ctnno", mySqlReader("CTNSTRING"))

                If mySqlReader("CTNSEALID") Is DBNull.Value Then
                    rpt1.SetParameterValue("ctnseal", "-")
                Else
                    rpt1.SetParameterValue("ctnseal", mySqlReader("CTNSEALID"))
                End If



                If mySqlReader("CTNUPGRADE") Is DBNull.Value Then


                    rpt1.SetParameterValue("agent", mySqlReader("CTNAGENT"))
                ElseIf mySqlReader("CTNUPGRADE") = "N" Then

                    rpt1.SetParameterValue("agent", mySqlReader("CTNAGENT"))

                ElseIf mySqlReader("CTNUPGRADE") = "U" Then
                    Dim ab As String
                    ab = mySqlReader("CTNAGENT") + Environment.NewLine
                    ab += "(UPGRADE)"
                    rpt1.SetParameterValue("agent", ab)
                Else

                End If


                rpt1.SetParameterValue("ctnsize", mySqlReader("CTNSIZE"))
                rpt1.SetParameterValue("shipper", mySqlReader("SHIPNAME"))
                rpt1.SetParameterValue("consignee", mySqlReader("BNFORWARDERNAME"))

                rpt1.SetParameterValue("transport", mySqlReader("COMNAME"))
                rpt1.SetParameterValue("carid", mySqlReader("CARID"))
                Dim splita() As String
                splita = Split(mySqlReader("VOYVESNAMES"), "/")

                rpt1.SetParameterValue("vesselname", splita(1))
                rpt1.SetParameterValue("voyage", "S" + Format(mySqlReader("VOYAGEID"), "000"))
                rpt1.SetParameterValue("POL", "PENANG")


                rpt1.SetParameterValue("tsport", "YKP")


                If mySqlReader("BFINALDEST") Is DBNull.Value Then
                    rpt1.SetParameterValue("pofd", "")
                Else
                    rpt1.SetParameterValue("pofd", mySqlReader("BFINALDEST"))
                End If

                rpt1.SetParameterValue("ctnlocation", "YKP DEPOT")

                rpt1.SetParameterValue("comudity", mySqlReader("BCOM"))
            End While
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        mysql.Close()
    End Sub

    Private Sub CrystalReportViewer1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CrystalReportViewer1.Load

    End Sub
End Class